import { Name, Dept } from '../../interface/employee'
import { UPDATE_CUREMPLOYEE_NAME, UPDATE_CUREMPLOYEE_DEPT } from '../../contants/actions';

type State = Readonly<{
  name: string | undefined;
  departmentId: number | undefined;
}>

type Action = {
  type: string;
  payload: Name | Dept;
}

const initialState: State = {
    name: '',
    departmentId: undefined
}

export default (state=initialState, action: Action) => {
  switch(action.type) {
    case UPDATE_CUREMPLOYEE_NAME:
      return {
        ...state,
        name: action.payload
      }
    case UPDATE_CUREMPLOYEE_DEPT:
      return {
        ...state,
        departmentId: action.payload
      }
    default:
      return state;
  }
}